/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package inet.controller;

import inet.dao.NotesDAO;
import inet.entity.Notes;
import java.math.BigDecimal;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

/**
 *
 * @author ÂuNgọcThái
 */
@ManagedBean
@SessionScoped
public class NotesController {

    /**
     * Creates a new instance of NotesController
     */
    private Notes note = null;
    private NotesDAO noteDAO = null;

    public NotesController() {
        note = new Notes();
        noteDAO = new NotesDAO();
    }

    public Notes getNote() {
        return note;
    }

    public void setNote(Notes note) {
        this.note = note;
    }

    public NotesDAO getNoteDAO() {
        return noteDAO;
    }

    public void setNoteDAO(NotesDAO noteDAO) {
        this.noteDAO = noteDAO;
    }


//    public String ccDate() {
//        DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
//        Date date = new Date();
//        return dateFormat.format(date);
//    }
//     public String lastUpdate() {
//        DateFormat dateFormat = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss");
//        Date date = new Date();
//        return dateFormat.format(date);
//    }

    public Notes showNotes(BigDecimal id) {
        note = noteDAO.showNotes(id);
        if (note == null) {
            noteDAO = new NotesDAO();
            if (noteDAO.addNotes(id ) == true) {
                note = noteDAO.showNotes(id);
                return note;
            } else {
                return null;
            }
        } else {
            return note;
        }
    }

    public String updateNote() {
        noteDAO = new NotesDAO();
        if (noteDAO.updateNotes(note.getContent(), note.getNote_id())) {
            //note= new Notes();
             note = noteDAO.showNoteByID(note.getNote_id());
             return "";
        }else{
            return "";
        }
    }
}
